package com.whcoding.test.controller;

import com.whcoding.test.pojo.OrmCustomerVO;
import com.whcoding.test.service.CustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import java.io.IOException;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-06-28 11:03
 **/
@RestController
@Validated
@RequestMapping("/testCustomer")
public class OrmCustomerTestController {

	@Autowired
	CustomerService customerService;
	/**
	 * 添加log信息
	 */
	private static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

	/**
	 * 1. Hutool导出
	 * http://localhost:9180/demo/ormCustomer/excelExportByHutoolDemo
	 *
	 * @param response
	 * @throws IOException
	 */
	@GetMapping("/exportByHutool")
	public void exportCustomer(HttpServletResponse response) throws IOException {
		OrmCustomerVO ormCustomerVO = new OrmCustomerVO();
		customerService.exportByHutool(ormCustomerVO, response);
	}

	/**
	 * 2.easy poi 导出excel
	 * http://localhost:9180/demo/ormCustomer/exportCustomer
	 *
	 * @return
	 */
	@GetMapping(value = "/exportByEasyPoi")
	public void exportByEasyPoi(HttpServletResponse response) throws IOException {
		customerService.exportByEasyPoi(response);
		logger.info("exportExcelTest方法执行完成!");
	}

	/**
	 * 3.hutool Page 分页查询数据
	 *
	 * @param pageable
	 * @return
	 */
	@GetMapping("/queryByHutoolPage")
	public ResponseEntity queryByHutoolPage(Pageable pageable) {
		return new ResponseEntity(customerService.queryByHutoolPage(pageable), HttpStatus.OK);
	}

	/**
	 * 4.下载模板
	 *
	 * @param response
	 * @throws IOException
	 */
	@GetMapping(value = "/downloadTemplate")
	public void downloadTemplate(HttpServletResponse response) throws IOException {
		customerService.downloadTemplate(response);
	}

	/**
	 * 5.JDBC 测试
	 */
	@GetMapping(value = "/jdbcTemplateTest")
	public void jdbcTemplateTest() {
		customerService.jdbcTemplateTest();
	}
}
